<template>

  <el-dialog
      :close-on-click-modal="false"
      destroy-on-close
      :show-close="false"
      width="30%"
      v-model="PINGJIASTATUS"
      title="面试评价"
  >
    <!-- <el-form ref="ruleFormRef" :model="formData" :rules="formRules" size="small" :inline="false" label-width="100px">
      <el-form-item label="主题" prop="title">
        <el-input v-model="formData.title" placeholder="请输入主题" maxlength="32" size="small"/>
      </el-form-item>
      <el-form-item label="候选人" prop="candidateId">
        <el-select v-model="formData.candidateId" placeholder="请选择候选人" @change="getLastInterview" size="small" filterable>
          <el-option v-for="item in candidateList" :key="item.id" :label="item.name" :value="item.id"/>
        </el-select>
      </el-form-item>
      <el-form-item label="面试时间">
        <span>{{ formData.actionStartTime }} - {{ formData.actionEndTime }}</span>
      </el-form-item>
      <el-form-item label="面试官">
        <span>{{ formData.interviewerNames }}</span>
      </el-form-item>
      <el-form-item label="面试轮次">
        <span>{{ formData.interviewRound }}轮</span>
      </el-form-item>
      <el-form-item label="优先度">
        <el-radio-group v-model="formData.priority">
          <el-radio :label="0" size="small">普通</el-radio>
          <el-radio :label="1" size="small">高</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="通知时间" prop="remindState">
        <el-radio-group v-model="formData.remindState">
          <el-radio v-for="item in remindTimes" :key="item.value" :label="item.value" size="small">{{ item.label }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="通知方式" prop="remindType">
        <el-checkbox-group v-model="formData.remindType" size="small">
          <el-checkbox label="1">应用、公众号通知</el-checkbox>
          <el-checkbox label="2">短信通知</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="备注信息">
        <el-input v-model="formData.remark" type="textarea" :rows="3" placeholder="请输入备注信息" size="small"/>
      </el-form-item>
    </el-form> -->
    <appraise-interview-form ref="form"></appraise-interview-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button size="large" @click="close()">取消</el-button>
        <el-button @click="submit()" type="primary" size="large">
          确认
        </el-button
        >
      </div>
    </template>
  </el-dialog>


</template>

<script>
// 面试评价

// import {onMounted, reactive, toRefs, ref} from 'vue'
// import {getListByType, getLastInterviewData} from '/@/api/oa/candidate'
// import {getRemindTimes} from '/@/api/matter'
// import {ElMessage} from 'element-plus';
// import {formatDate} from '/@/utils/formatTime'
// import {homeApi} from "/@/api/home/index";
// import {format} from "/@/views/home/component/lib/utils";

// const homeCalendar = homeApi();
import AppraiseInterviewForm from '/@/views/matter/components/AppraiseInterviewForm.vue'
export default {
  name: 'AppraiseInterview',
  props: {
    PINGJIASTATUS: {
      type: Boolean,
      default: true,
    },
    idw: {
      type: String,
      default: "",
    },
    thisTime: {
      type: String,
      default: "",
    },
  },
  emits: ["PingJiaCloseClose"],
  components: {
    AppraiseInterviewForm
  },
  setup(props, context) {
    const form = ref()
    const state = reactive({
      // formData: {
      //   candidateId: null,
      //   title: '面试评价',
      //   interviewStartTime: null,
      //   interviewEndTime: null,
      //   executorIds: '',    // 拿最新面试记录获取当时的面试官id, 逗号隔开
      //   interviewerNames: '',   // 面试官名称
      //   actionStartTime: null,  // 拿最新面试记录的面试开始时间
      //   actionEndTime: null,    // 拿最新面试记录的面试结束时间
      //   interviewRound: 1,   // 自动统计面试次数
      //   interviewDiscuss: [],   // 面试评价, 格式如：[{"content":"评价内容","userName":"评价人名称"}]
      //   remark: null,    // 备注
      //   remindState: 'NONE',     // 提醒时间, 根据枚举类MatterRemindTimeEnum
      //   remindType: [],     // 提醒方式, 多选
      //   state: 1,           // 状态 -1草稿 0未开始 1进行中 2已完成 3已退回  4已取消 5已撤回
      //   priority: 0        // 优先级 0普通 1重要
      // },
      // candidateList: [],
      // remindTimes: []
    })
    // const ruleFormRef = ref({});
    // const formRules = reactive({
    //   candidateId: {required: true, message: '请选择候选人', trigger: 'change'},
    //   title: {required: true, message: '请填写主题', trigger: 'change'}
    // })
    let close = () => {
      form.value.reset()
      context.emit("PingJiaCloseClose");
      // resetForm()
    };
    let submit = async () => {
      form.value.submit()
      // state.formData.occurDate = format(state.occurDate, 'yyyy-MM-dd HH:mm')
      // state.formData.settlementDate = format(state.settlementDate, 'yyyy-MM-dd HH:mm')
      // state.form.id = idw.value;
      // if (!formEl) return;
      // await formEl.validate((valid, fields) => {
      //   if (valid) {
      //     console.log(state.formData);

      //     // state.formData.executorIds = JSON.stringify(state.formData.executorIds)
      //     homeCalendar.addInterviewEvaluate(state.formData).then((res) => {
      //       if (res.code === 0) {
      //         resetForm(formEl)
      //         close(formEl)
      //       }
      //     });
      //   } else {
      //     console.log("error submit!", fields);
      //   }
      // });

      // console.log(state.formData);
      // state.form.id = idw.value
      // homeCalendar
      //   .modifyMatter(state.formData)
      //   .then((res) => {
      //       if(res.code===1){

      //       }
      //   });
    };
    // const resetForm = (formEl) => {
    //   if (!formEl) return
    //   formEl.resetFields()
    // }
    // const getLastInterview = () => {
    //   // 如果候选人为空, 结束加载面试记录数据
    //   if (!state.formData.candidateId) {
    //     return false
    //   }
    //   getLastInterviewData(state.formData.candidateId).then(res => {
    //     if (res.data) {
    //       state.formData.executorIds = res.data.interviewers
    //       state.formData.interviewerNames = res.data.interviewerNames
    //       state.formData.interviewStartTime = res.data.interviewTimeStart
    //       state.formData.interviewEndTime = res.data.interviewTimeEnd
    //       state.formData.interviewRound = res.data.interviewRound
    //     } else {
    //       ElMessage.error('未查询到该候选人的面试记录！')
    //     }
    //   })
    // }
    // onMounted(() => {
    //   state.formData.actionStartTime = state.formData.actionEndTime = formatDate(new Date(), 'YYYY-mm-dd HH:MM:SS')
    //   getLastInterview()
    //   getRemindTimes().then(res => state.remindTimes = res.data)
    //   // 获取已面试的
    //   getListByType('3').then(res => state.candidateList = res.data)
    // })
    return {
      ...toRefs(state),
      // getLastInterview,
      submit,
      close,
      form
      // formRules,
      // ruleFormRef,
      // resetForm,
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
